<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="<?=domain?>static/style/treeTable.css" rel="stylesheet" type="text/css" />
<link href="<?=domain?>static/style/manage.css" rel="stylesheet" type="text/css" />
<link href="<?=domain?>static/style/fancybox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=domain?>static/scripts/core.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/fancybox.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/treeTable.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/manage.js" charset="utf-8"></script>
<title><?=name?></title>
<body>
<div class="boxtitle">权限分配</div>
<form name="purview" method="post" action="<?=domain?>index.php?c=role&a=purview" onsubmit="return RequestPost('purview');">
<input type="hidden" name="role" value="<?=$role?>"/>
<div class="area box">
<table class="example table-list">
  <tbody>
      <?php
      	function recursive($data,&$current){
      		foreach($data as $key=>$value){
      ?>
	  <tr id="node-<?=$value['id']?>"<?php if($value['parent']!=0){echo ' class="child-of-node-'.$value['parent'].'"';}?>>
		<td><div><input type='checkbox' name='purview[]' value="<?=$value['id']?>" id="purview_<?=$value['id']?>"<?php if(!empty($value['method'])){if(isset($current[$value['controller']][$value['method']])){echo ' checked';}}?>><label for="purview_<?=$value['id']?>"><?=$value['name']?></label></div></td>
	  </tr>
      <?php
      		if(isset($value['child'])){recursive($value['child'],$current);}
      		}
      	}
      	recursive($menu,$current);
      ?>
  </tbody>
</table>
</div>
<div class="boxbu">
	<input type="submit" name="save" value="确定" class="yellow"/>
</div>
</form>
</body>
</html>
<script language="JavaScript" type="text/javascript">
var rec_1=function(obj){
  var parent=$(obj).parents('tr').attr('class');
  if(typeof parent==='string'){
  	parent=(/child-of-\S+/g).exec(parent);
  	if(parent!==null){
	  	var top=parent[0].slice(9,parent[0].length);
	  	var input=$('#'+top).find('td > div >input');
	  	input.attr('checked',true);rec_1(input);
  	}
  }
}
var rec_2=function(obj,action){
  var child=$(obj).attr('id');
  $('.child-of-'+child).each(function(){
  	$(this).find('td > div >input').attr('checked',action);
  	rec_2(this,action);
  });
}
$("input[checked]").each(function(index){rec_1(this);});
$(".example").treeTable();
$("tbody > tr").click(function(){
	var input=$(this).find('td > div >input');
	var action=input.attr('checked')?true:false;
	if(action){rec_1(input);}
	rec_2(this,action);
});
</script>